package com.link2room.rodimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.*;
import com.link2room.rodimus.dto.param.inside.SalesmanInComeDetailInsideParamDto;
import com.link2room.rodimus.facade.ISalesmaManagerFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/2/20.
 */
@Component("salemanAwardReservationRunner")
public class SalemanAwardReservationRunnerImpl implements Worker {

    @Resource
    private ISalesmaManagerFacadeService salesmanManagerFacadeService;

    @Override
    public boolean exec(Message message) throws Exception {
        SalesmanInComeDetailInsideParamDto paramDto = JacksonUtil.jsonToBean(message.getMessageBody(),SalesmanInComeDetailInsideParamDto.class);
        try {
            if(message.getDequeueCount()<=3){
                salesmanManagerFacadeService.paySalesmanAwardReservationStep(paramDto);
            }else {
                BatchUtil.doBatchTaskFail(paramDto.getTaskMainId(),paramDto.getTaskId(), BaseSysExceptionEnum.MNS_COUNT_ABOVE.getMsg());
            }
            return true;
        }catch (Exception e){
            String errorDetail= ExceptionUtil.getExceptionDetail(e);
            LogUtil.logger.error(errorDetail);
            return false;
        }
    }
}
